﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VISS.API.Admins;
using NCT.Framework;

namespace VISS.Web.BackEnd.Modules.Admin {

    public partial class ChangePasswordPage : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

        }
        protected void ChangePasswordBox_ChangingPassword(object sender, LoginCancelEventArgs e) {
            AdminEnt item = AppSettings.GetAdminLogin(Session);
            string password = StringUtils.DoMD5(ChangePasswordBox.CurrentPassword);
            if (item.Password != password) {
                lbl_Changed.Visible = false;

                lbl_Error.Text = "Sai Mật khẩu cũ";
                lbl_Error.Visible = true;

                e.Cancel = true;
                return;
            }

            string newPassword = ChangePasswordBox.NewPassword;
            item.Password = newPassword;

            if (AdminBC.UpdatePassword(item)) {
                lbl_Changed.Visible = true;
                lbl_Error.Visible = false;

                item.Password = StringUtils.DoMD5(newPassword);
                AppSettings.SetAdminLogin(Session, item);

                e.Cancel = true;
            }
            else {
                lbl_Changed.Visible = false;

                lbl_Error.Text = "Lỗi hệ thống";
                lbl_Error.Visible = true;

                e.Cancel = true;
            }
        }
    }
}